// pages/templates/cash/cashs.js
import service from '../../../services/conch';
import base from '../../../config/base.js';


Component({
  /**
   * 组件的属性列表
   */
  properties: {
    scrolltop: {
      type: Number,
      observer: function (newVal, oldVal, changedPath) {
        this.cashHandle(newVal, oldVal)
      }
    },
    sign_type: {
      type: Number,
    },
    coupons: {
      type: Object
    },
    sevensignbox_flag: {
      type: Boolean,
      value: ''
    },
    sevensignbox_time: {
      type: String,
      value: ''
    },
    loadsSevenSingBloean: {
      type: Number,
      observer: function (newVal, oldVal, changedPath) {
        if (newVal !=1){
         this.sevenSignTipHandle()
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    newVal:'',
    oldVal: '',
    cashs_box: false,
    cash_flag_left:'',//签到领取左边
    cash_flag_right: '',//签到领取右边   
    sign_bgc: base.static + 'conch/sevensign3.png',
    sign_orderbtn_img: base.static + 'conch/order-btn.png',
    red_icon: base.static + 'conch/group11.png',
    lingxianjin_icon: base.static + 'conch/lingxianjin-img.gif',
    sign_type: '',
    sevensignbox_flag: false,
    coupons:''
  },
  ready(){
    setTimeout(()=>{
      this.setData({
        cash_flag_right: 2
      })
    },3000)
    
    this.setData({
      sign_type: this.properties.sign_type,
      coupons: this.properties.coupons,
      sevensignbox_flag: this.properties.sevensignbox_flag,
      sevensignbox_time: this.properties.sevensignbox_time
    })
    
  },
  /**
   * 组件的方法列表
   */
  methods: {
    timeout:null,
    cashHandle(newVal, oldVal){
      if (newVal > oldVal) {
        if (this.timeout){
          clearTimeout(this.timeout)
        }
        this.setData({
          cash_flag_right: 1
        })
        this.timeout = setTimeout(()=>{
          this.setData({
            cash_flag_right: 2
          })
        },3000)
      }else if (newVal < oldVal){
        if (this.timeout) {
          clearTimeout(this.timeout)
        }
        this.setData({
          cash_flag_right: 2
        })
      }
    },
    //领取3元红包显示和隐藏
    sevenSignTipHandle() {
      let that = this;
      service.signdayremind({}, function (res) {
        if (res && res.code == 1) {
          if (res.data.status == 1){
            that.setData({
              cashs_box: true,
              sevensignbox_time: res.data.time
            })
          } else if (res.data.status == 0){
            that.setData({
              cashs_box: false
            })
          }
        }
      })
    },
    opensevensignbox(){
      this.setData({
        sevensignbox_flag: true
      })
    },
    //关闭弹框
    closeSevenbox() {
      if (this.data.coupons && this.data.coupons !=""){
        let myEventDetail = {
          coupons_flag: true
        }
        this.triggerEvent('myevent', myEventDetail)
      }
      this.setData({
        sevensignbox_flag: false
      })
    },
  }
  



})
